<?php
declare (strict_types = 1);

namespace app\adminapi\controller\system;

use adminmatrix\admin\BaseController;
use adminmatrix\admin\service\JsonService;
use app\adminapi\logic\system\ConfigLogic;
use think\Request;
use hg\apidoc\annotation as Apidoc;
use think\response\Json;

#[
    Apidoc\Title("系统配置"),
    Apidoc\Group("config"),
]
class ConfigController extends BaseController
{
    #[
        Apidoc\Title("系统配置列表"),
        Apidoc\Tag("系统配置")
    ]
    public function lists() : Json
    {
        return $this->dataLists();
    }


    #[
        Apidoc\Title("新增tag配置"),
        Apidoc\Method("POST")
    ]
    public function addGroup(Request $request , ConfigLogic $config) : Json{
        try {
            $config -> addGroup($request);
            return JsonService::success('新增配置组成功');
        } catch (\Exception $e)
        {
            return JsonService::fail($e->getMessage());
        }
    }

    public function save(Request $request , ConfigLogic $config) :Json
    {
        try {
            $config-> save($request);
            return  JsonService::success('新增配置成功');
        } catch (\Exception $e)
        {
            return JsonService::fail($e->getMessage());
        }
    }


    public function update(Request $request , ConfigLogic $config) : Json
    {
        try {
            $config -> updateConfig($request);
            return JsonService::success('更新成功');
        } catch (\Exception $exception)
        {
            return JsonService::fail($exception->getMessage());
        }
    }

    public function delete(Request $request ,ConfigLogic $config): Json
    {
        try {
            $config -> deleteConfig($request);
            return JsonService::success('删除配置成功');
        } catch (\Exception $exception)
        {
            return JsonService::fail($exception->getMessage());
        }
    }
}
